package com.retoc.graduationtravel.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.retoc.graduationtravel.common.ApiRestResponse;
import com.retoc.graduationtravel.domain.City;
import com.retoc.graduationtravel.domain.resp.CityResp;
import com.retoc.graduationtravel.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/city")
public class CityController {
    @Autowired
    CityService cityService;

    @GetMapping("list")
    public ApiRestResponse<List<CityResp>> list() {
        List<City> list = cityService.list();
        List<CityResp> result = new ArrayList<>();
        for (City city : list) {
            CityResp cityResp = new CityResp();
            cityResp.setValue(city.getId().toString());
            cityResp.setLabel(city.getName());
            cityResp.setSpell(city.getSpell());
            result.add(cityResp);
        }
        return ApiRestResponse.success(result);
    }

    //按照首字母返回
    @GetMapping("acronym")
    public ApiRestResponse<Map<String, List<City>>> acronym() {
        Map<String, List<City>> cities = cityService.getacronym();
        return ApiRestResponse.success(cities);
    }

    @GetMapping("/hotcity")
    public ApiRestResponse<List<City>> hotcity() {
        QueryWrapper<City> qw = new QueryWrapper<>();
        qw.eq("hot_city", 1);
        List<City> list = cityService.list(qw);
        return ApiRestResponse.success(list);
    }
}
